package org.jeecg.modules.carPersonnel.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.carInformation.entity.CarInformation;
import org.jeecg.modules.carPersonnel.entity.CarPersonnel;
import org.jeecg.modules.carPersonnel.mapper.CarPersonnelMapper;
import org.jeecg.modules.carPersonnel.service.ICarPersonnelService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description: 车辆人员关联表
 * @Author: jeecg-boot
 * @Date:   2024-07-23
 * @Version: V1.0
 */
@Service
public class CarPersonnelServiceImpl extends ServiceImpl<CarPersonnelMapper, CarPersonnel> implements ICarPersonnelService {

    @Override
    public List<CarInformation> getCarInformation(String openId) {
        return baseMapper.getCarInformation(openId);
    }

    @Override
    public CarPersonnel getByOpenIdAndPlateNo(String openId, String plateNo) {
        LambdaQueryWrapper<CarPersonnel> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(CarPersonnel::getOpenId, openId);
        wrapper.eq(CarPersonnel::getPlateNo, plateNo);
        return baseMapper.selectOne(wrapper);
    }

    @Override
    public List<String> getPlateNoByOpenId(String openId, String plateNo) {
        LambdaQueryWrapper<CarPersonnel> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(CarPersonnel::getOpenId, openId);
        wrapper.like(StringUtils.isNotBlank(plateNo), CarPersonnel::getPlateNo, plateNo);
        List<CarPersonnel> carPersonnelList = baseMapper.selectList(wrapper);
        return carPersonnelList.stream().map(CarPersonnel::getPlateNo).collect(Collectors.toList());
    }
}
